'use strict';
 const db = uniCloud.database();

exports.main = async (event, context) => {
  //event为客户端上传的参数
  // console.log('event : ' + event)
	const collection_users = db.collection('users');
	const collection_products =  db.collection('products');
	let user_id=event.user_id;
	let products=[];
	let res=await collection_users.doc(user_id).get()
	let list=res.data[0].my_buys;
	for(let i=0; i<list.length; i++){
		let tmp_id=list[i]
		res=await collection_products.doc(tmp_id).get()
		let pro=res.data[0];
		products.push(pro);
	}

  //返回数据给客户端
  return {status:2,"products":products}
};
